/*
 * RecorderSettings.java
 *
 * Copyright (C) 2005-2008 Tommi Laukkanen
 * http://www.substanceofcode.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package uns.fit.gis.settings;

import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.midlet.MIDlet;

import uns.fit.gis.Util;


/**
 * RecorderSettings contains all settings for the Trail Explorer application.
 * Current settings are: - GPS unit connection string - Export folder (default
 * C:/)
 * 
 * @author Tommi Laukkanen
 */
public class MapSettings {

    /**
     * Settings save/load handler
     */
    private static Settings settings;

    private final String LOCALE = "locale";
    private final String DEVICE_ID = "device_id";
    private final String SERVER_DELAY_TIME = "server_delay_time";
    private final String URL_REGISTER = "url_register";
    private final String URL_UPDATE_LOCATION = "url_update_location";
    private final String STREET_NAME_IS_ALONG = "street_name_is_along";
    private final String UPDATE_POSITION = "update_postion";
    private final String STORAGE_FOLDER = "storage_folder";
    private final String NUMBER_USER_LOCATIONS = "number_user_locations";
    private final String OSM_USERNAME = "osm_username";
    private final String OSM_PASSWORD = "osm_password";
    /** 
     * Creates a new instance of RecorderSettings
     * @param midlet 
     */
    public MapSettings() {
        try {
            settings = Settings.getInstance();
        } catch (Exception ex) {
            
        }
    }

    public void setServerDelayTime(int time) {
    	settings.setIntProperty(SERVER_DELAY_TIME, time);
    }
    
    public int getServerDelayTime() {
    	return settings.getIntProperty(SERVER_DELAY_TIME, Util.SERVER_DELAY_TIME);
    }
    
    public void setLocale(String locale) {
    	settings.setStringProperty(LOCALE, locale);
    }
    
    public void setDeviceId(int id) {
    	settings.setIntProperty(DEVICE_ID, id);
    }
    
    public void setUrlRegister(String url) {
    	settings.setStringProperty(URL_REGISTER, url);
    }
    
    public void setUrlUpdatePosition(String url) {
    	settings.setStringProperty(URL_UPDATE_LOCATION, url);
    }
    
    public String getLocale() {
    	return settings.getStringProperty(LOCALE, "en");
    }
    
    public int getDeviceId() {
    	return settings.getIntProperty(DEVICE_ID, Util.DEVICE_ID);
    }
    
    public String getUrlRegister() {
    	return settings.getStringProperty(URL_REGISTER, Util.REGISTER_URL);
    }
    
    public String getUrlUpdatePosition() {
    	return settings.getStringProperty(URL_UPDATE_LOCATION, Util.UPDATE_POSITION_URL);
    }
    
    public boolean getStreetNameIsAlong() {
    	return settings.getBooleanProperty(STREET_NAME_IS_ALONG, Util.STREET_NAME_IS_ALONG);
    }
    
    public void setStreetNameIsAlong(boolean value) {
    	settings.setBooleanProperty(STREET_NAME_IS_ALONG, value);
    }
    
    public boolean getUpdatePosition() {
    	return settings.getBooleanProperty(UPDATE_POSITION, Util.UPDATE_POSITION);
    }
    
    public void setUpdatePostion(boolean value) {
    	settings.setBooleanProperty(UPDATE_POSITION, value);
    }
    
    public String getStorageFolder() {
    	return settings.getStringProperty(STORAGE_FOLDER, Util.STORAGE_FOLDER);
    }
    
    public void setStorageFolder(String value) {
    	settings.setStringProperty(STORAGE_FOLDER, value);
    }
    
    public int getNumberOfUserLocations() {
    	return settings.getIntProperty(NUMBER_USER_LOCATIONS, 0);
    }
    
    public void setNumberOfUserLocations(int value) {
    	settings.setIntProperty(NUMBER_USER_LOCATIONS, value);
    }
    
    public String getOSMUsername() {
    	return settings.getStringProperty(OSM_USERNAME, Util.OSM_USERNAME);
    }
    
    public void setOSMUsername(String value) {
    	settings.setStringProperty(OSM_USERNAME, value);
    }

    public String getOSMPassword() {
    	return settings.getStringProperty(OSM_PASSWORD, Util.OSM_USERNAME);
    }
    
    public void setOSMPassword(String value) {
    	settings.setStringProperty(OSM_PASSWORD, value);
    }
    
    public void save() {
        try {
            settings.save(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}